import { reqBannerList, reqCategoryList, reqFloorList } from "@/api"

export default {
  state: {
    categoryList: [],
    bannerList:[],
    floorList:[]
  },
  mutations: {
    // state接收到的是这个模块自己的state
    UPDATE_CATEGORYLIST(state, categoryList) {
      state.categoryList = categoryList
    },
    UPDATE_BANNERLIST(state,bannerList){
      state.bannerList=bannerList
    },
    UPDATE_FLOORLIST(state,floorList){  //这里的形参可以接收到state的数据
      state.floorList=floorList
    }

  },
  actions: {
    async getCategoryList({ commit }) {
      const result = await reqCategoryList()
      if (result.code === 200) {
        commit("UPDATE_CATEGORYLIST", result.data.slice(0, 15))
      }
    },
    async getBannerList({commit}){
      const result=await reqBannerList()
      if(result.code===200){
        commit('UPDATE_BANNERLIST',result.data)
      }
    },
    async getFloorList({commit}){
      const result=await reqFloorList()
      if(result.code===200){
        commit('UPDATE_FLOORLIST',result.data)
      }
    }
  },
  getter: {},
}
